package com.xyh.transaction.controller;

import com.github.pagehelper.PageInfo;
import com.xyh.transaction.entity.Button;
import com.xyh.transaction.entity.dto.button.ButtonEditOrAddDto;
import com.xyh.transaction.entity.dto.button.ButtonSearchDto;
import com.xyh.transaction.entity.dto.user.ArrDto;
import com.xyh.transaction.response.ResponseResult;
import com.xyh.transaction.service.ButtonService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

@Slf4j
@Api(tags = "按钮权限管理")
@RestController
@RequestMapping("/button")
public class ButtonController {


    @Autowired
    private ButtonService buttonService;

    @ApiOperation(value = "页面按钮权限", notes = "返回当前用户页面对应按钮权限")
    @GetMapping("/auth")
    public ResponseResult<Map<String, List<String>>> buttonList() {

        Map<String, List<String>> buttonList = buttonService.getUserAuthButtonList();

        return ResponseResult.success("查询成功！", buttonList);
    }

    @ApiOperation(value = "按钮权限列表" , notes = "返回所有的按钮权限列表")
    @PostMapping("list")
    public ResponseResult<PageInfo<Button>> list(@RequestBody ButtonSearchDto buttonSearchDto){

        PageInfo<Button> buttonAuthList = buttonService.getButtonAuthList(buttonSearchDto);

        return ResponseResult.success("查询成功！",buttonAuthList);
    }

    @ApiOperation(value = "新增按钮权限" , notes = "添加新的按钮权限")
    @PostMapping("add")
    public ResponseResult<Void> add(@RequestBody ButtonEditOrAddDto buttonEditOrAddDto){
        buttonService.addButton(buttonEditOrAddDto);
        return ResponseResult.success("操作成功！",null);
    }

    @ApiOperation(value = "修改按钮权限" , notes = "修改按钮权限根据id")
    @PostMapping("edit")
    public ResponseResult<Void> edit(@RequestBody ButtonEditOrAddDto buttonEditOrAddDto){
        buttonService.editButton(buttonEditOrAddDto);
        return ResponseResult.success("操作成功！",null);
    }

    @ApiOperation(value = "删除按钮权限" , notes = "根据id删除按钮权限")
    @PostMapping("delete")
    public ResponseResult<Void> edit(@RequestBody ArrDto arrDto){
        buttonService.deleteButton(arrDto);
        return ResponseResult.success("操作成功！",null);
    }

}
